using System.Collections;
using UnityEngine;

namespace Spine.Unity.Examples {
    /// <summary>
    /// Spineboy基础输入控制脚本
    /// 处理角色移动、攻击、瞄准和跳跃的输入事件
    /// </summary>
    public class SpineboyBeginnerInput : MonoBehaviour {
        
        #region Inspector 配置区域
        [Header("输入轴配置")]
        [Tooltip("水平移动输入轴名称")]
        public string horizontalAxis = "Horizontal";
        
        [Tooltip("攻击按钮名称")]
        public string attackButton = "Fire1";
        
        [Tooltip("瞄准按钮名称")]
        public string aimButton = "Fire2";
        
        [Tooltip("跳跃按钮名称")]
        public string jumpButton = "Jump";

        [Header("角色模型")]
        [Tooltip("关联的Spineboy模型组件")]
        public SpineboyBeginnerModel model;

        /// <summary>
        /// 验证模型组件有效性
        /// 自动获取关联的SpineboyBeginnerModel组件
        /// </summary>
        void OnValidate () {
            if (model == null)
                model = GetComponent<SpineboyBeginnerModel>();
        }
        #endregion

        /// <summary>
        /// 每帧更新输入处理
        /// 处理移动、攻击、瞄准和跳跃输入事件
        /// </summary>
        void Update () {
            if (model == null) return;

            // 处理水平移动输入
            float currentHorizontal = Input.GetAxisRaw(horizontalAxis);
            model.TryMove(currentHorizontal);

            // 处理攻击输入
            if (Input.GetButton(attackButton))
                model.TryShoot();

            // 处理瞄准输入（按钮按下开始瞄准，松开停止）
            if (Input.GetButtonDown(aimButton))
                model.StartAim();
            if (Input.GetButtonUp(aimButton))
                model.StopAim();

            // 处理跳跃输入
            if (Input.GetButtonDown(jumpButton))
                model.TryJump();
        }
    }
}